// pages/my/vipOrder/vipReplaceDetail.js
 const app = getApp()
Page({
  data: {
    goods:[],
    oldGoods:[],
    payTypePicker:true,
    payTypeChecked:true,
    goodsPriceShow:true,
    actualPriceShow:true,
    goodsInfoShow:true,
    newTotalPrice:0,
    oldTotalPrice:0,
    orderNo:'',
    orderTime:'',
    saler:'',
    orderId:'',
    company_name:''
  },
  onLoad: function (options) {
    let orderId = options.orderId
    this.setData({
      orderId,
    })
    this.getOrderDetail(orderId)
  },
  onShow: function () {

  },
  getOrderDetail(orderId){
    wx.showLoading({
      title:'正在加载'
    })
    let that = this
    let data = {
      orderId
    }
    console.log(data)
    app.request('wx_app/user_order/detail',data,'GET').then(res=>{
      console.log(res)
      if (res.code==1) {
        let goods = [],
        oldGoods = []
        res.data.orderDetails.forEach(item=>{
          goods.push({
            url:item.pic,
            name:item.name,
            price:item.price,
            actualPrice:item.actualPrice,
            num:item.amount,
            type:item.des,
            id:item.productId,
            color:item.tagColor,
            companyName:item.productTag
          })
        })
        res.data.oldSkus.forEach(item=>{        
          oldGoods.push({
            url:item.mainImgUrl,
            name:item.productName,
            price:item.stockPrice,
            num:item.amount,
            type:item.versionValues,
            imgs:[item.imgUrl2,item.imgUrl3,item.imgUrl4,item.imgUrl5],
            color:item.tagColor,
            companyName:item.productTag,
            direct:item.status==0?"入库":"废弃",
            discardPrice:item.discardPrice
          })
        })
        that.setData({
          goods,
          oldGoods,
          payWay:res.data.payWay,
          orderNo:res.data.orderNo,
          orderTime:res.data.createTime,
          saler:res.data.accountName,
          company_name:res.data.company_name
        })
        that.totalPrice()
        wx.hideLoading()
      }else{
        wx.hideLoading()
        app.errorMsg(res.message)
      }
    })
  },
  totalPrice(){
    let newTotalPrice = 0,
        oldTotalPrice = 0
    this.data.goods.forEach(item=>{
      newTotalPrice += item.actualPrice*item.num
    })
    this.data.oldGoods.forEach(item=>{
      oldTotalPrice += item.price*item.num
    })
    this.setData({
      newTotalPrice,
      oldTotalPrice
    })
  },
})